﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using Entities;
using BLL.Validation;

namespace BLL
{
    public class DiemThiManager: IValidator<DiemThi>
    {
        public static ActionResultAsList<DiemThi> LayDanhSachDiemThi()
        {
            var aResult = new ActionResultAsList<DiemThi>();
            try
            {
                aResult.Result = DiemThiProvider.LayDanhSachDiemThi();
            }
            catch (Exception ex)
            {
                aResult.Exceptions.Add(ex);
            }
            return aResult;
        }

        public static ActionResultAsList<DiemThi> TimDanhSachDiem(object a, SoSanh ss)
        {
            var aResult = new ActionResultAsList<DiemThi>();
            try
            {
                aResult.Result = DiemThiProvider.TimDanhSachDiem(a, ss);
            }
            catch (Exception ex)
            {
                aResult.Exceptions.Add(ex);
            }
            return aResult;
        }

        public static ActionResult<int> ThemDiemThi(DiemThi diemthi)
        {
            var aResult = new ActionResult<int>();
            try
            {
                aResult.Result = DiemThiProvider.ThemDiemThi(diemthi);
                if (aResult.Result <= 0)
                {
                    aResult.Exceptions.Add(new Exception("Thêm điểm thi không thành công"));
                }
            }
            catch (Exception ex)
            {
                aResult.Exceptions.Add(ex);
            }
            return aResult;
        }


        public static ActionResult<bool> XoaDiemThi(int maKyThi, int maKH, int maHV)
        {
            var aResult = new ActionResult<bool>();
            try
            {
                aResult.Result = DiemThiProvider.XoaDiemThi(maKyThi, maKH, maHV);
                if (!aResult.Result)
                {
                    aResult.Exceptions.Add(new Exception("Xóa điểm thi không thành công"));
                }
            }
            catch (Exception ex)
            {
                aResult.Exceptions.Add(ex);
            }
            return aResult;
        }



        public static ActionResult<bool> CapNhatDiemThi(DiemThi diemthi)
        {
            var aResult = new ActionResult<bool>();
            try
            {
                aResult.Result = DiemThiProvider.CapNhatDiemThi(diemthi);
                if (!aResult.Result)
                {
                    aResult.Exceptions.Add(new Exception("Cập nhật thông tin điểm thi không thành công"));
                }
            }
            catch (Exception ex)
            {
                aResult.Exceptions.Add(ex);
            }
            return aResult;
        }


        public ValidationResult Validate(DiemThi obj)
        {
            var vResult = new ValidationResult();

            if (string.IsNullOrEmpty(obj.KetQua.Trim()))
            {
                vResult.Message.Add("Kết quả điểm thi khác chuỗi rỗng");
            }           
            return vResult;
        }
    }
}
